  <?php $this->set('title_for_layout', 'My Favorite'); ?>
<div class="tab-content"><?php
    //var_dump($this->Session->read('order'));
   $j=0;
    foreach ($favoriteproducts as $product):
			echo '<div class="item">';
                        $image=$product['Product']['picture1'];
			if(empty($image)){
                            $image = 'default_product.png';
                            $resizedFile = $this->webroot.'img/uploads/'.$image;
                        }else {
                           $resizedFile = $this->webroot.'img/uploads/images_resize/'.$image;
                        }
			echo '<a href="'.$this->webroot.'posts/view/'.$product['Product']['id'].'"><img style="width: 100px; "src="'.$resizedFile.'"/></a>';
			if (strlen($product['Product']['title']) > 30) {
                            echo '<span class="pro-title">'.$this->Html->link(substr($product['Product']['title'], 0, 30).'...', array('controller' => 'posts', 'action' => 'view', $product['Product']['id'])).'</span>';
                        }else {
                            echo '<span class="pro-title">'.$this->Html->link($product['Product']['title'], array('controller' => 'posts', 'action' => 'view', $product['Product']['id'])).'</span>';
                        }
			echo '<span id="pro-price">$'.$product['Product']['price'].'<i class="'.$product['Product']['status'].'"></i></span>';
			echo '<span id="modified_date">'.$product['Product']['modified_date'].'</span>';
                        if($product['User']['first_name']) {echo '<span id="auth">'.$product['User']['first_name'].'</span>';}
                        if($product['Location']['name']) {echo '<span id="address">'.$product['Location']['name'].'</span>';}
			echo '<span id="phone">'.$product['User']['phone'].'</span><br>';
			if (strlen($product['Product']['description']) > 150) {
                            echo '<span id="dec">'.substr($product['Product']['description'], 0, 150).'...'.'</span>';
                        }else {
                            echo '<span id="dec">'.$product['Product']['description'].'</span>';
                        }
                        echo '<div class="total-view">';
                        echo '<span class=remove>'.$this->Html->link(' ', array('controller'=>'posts','action'=>'deletefavorite', $j)).'</span>';
                        if($product['Product']['view']) {
                            echo '<span class="total-product">View :'.$product['Product']['view'].'</span>';
                        }else {
                            echo '<span class="total-product">View : 0</span>';
                        }
                        $i = 0;
                        for($a=1; $a<=4; $a++){
                            $picture = "picture$a";
                            if($product['Product'][$picture]){
                                $i++;
                            }
                        }
                        echo '<span class="total-image">'.$i.'</span>';
                       
                        echo '<span class="total-comment">'.count($product['Comment']).'</span>';
                        $total = 0;
//                        foreach ($counttoday as $today) {
//                            if($product['Product']['id'] == $today['Statistic']['product_id']) {
//                                $total = $today['Statistic']['count'];
//                            }
//                        }
//                        echo '<apan class="total-today"> Today viewed:'.$total.'</span>';
                        echo '</div>';
			echo '<div class="clearfix"></div></div>';
                        $j++;
		endforeach;
?></div>
<script>
    
    jQuery(".removefav").click(
            function(e)
            {  e.preventDefault();
                var id=jQuery(this).attr('data');
                jQuery.ajax({
                    type:'POST',
                    url: '<?php echo Router::Url(array('controller' => 'posts', 'action' => 'deletefavorite')); ?>/'+id,
                    success: function(response) {  
                       //alert('delete');
                       location.reload(); 
                    },
                    data:jQuery('form').serialize()
                });
                return false;
            }
    );
</script>